package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.result.Result;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealOverViewVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 分页查询套餐
     * @param setmealPageQueryDTO
     * @return
     */
//    @Select("select * from setmeal where is_deleted = 0")
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 新增套餐
     * @param setmeal
     */
//    @Insert("insert into setmeal (category_id, name, price, description, image, create_time, update_time, create_user, update_user) VALUES " +
//            "(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    void save(Setmeal setmeal);

    /**
     * 根据id查询套餐
     * @param id
     */
    @Select("select * from setmeal where is_deleted = 0 and id = #{id}")
    Setmeal getById(Long id);

    /**
     * 修改套餐
     * @param setmeal
     */
    @Update("update setmeal set category_id = #{categoryId},name = #{name},price = #{price},description = #{description},image = #{image}," +
            "update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    /**
     * 停售起售
     * @param setmeal
     */
    @Update("update setmeal set status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void status(Setmeal setmeal);

    /**
     * 删除套餐
     * @param id
     */
    @Update("update setmeal set is_deleted = 1 where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void delSetmeal(Long id);

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    List<SetmealVO> list(Long categoryId);

    /**
     * 根据套餐id查询包含的菜品
     * @param setmealId
     * @return
     */
    List<DishItemVO> listDish(Long setmealId);

    /**
     * 查询套餐总览
     * @return
     */
    Integer getSetmeaStatus(Integer status);

}
